<template>
  <div>
    <div>
      <el-button-group>
        <el-button
          type="success"
          size="mini"
          @click="addline"
          class="el-icon-tickets"
          >开票</el-button
        >
      </el-button-group>
    </div>
    <el-table
      :data="rows"
      border
      :header-cell-style="getRowClass"
      show-summary
      :summary-method="computeSummary"
    >
      <el-table-column
        :label="item[0]"
        :min-width="item[3]"
        align="center"
        :prop="item[1]"
        :show-overflow-tooltip="item[4]"
        v-for="(item, index) in header"
        :key="index"
      >
        <template v-if="item[5] !== ''">
          <el-table-column
            v-for="(item2, index2) in item[5]"
            :label="item2[0]"
            :prop="item2[1]"
            sortable
            :show-overflow-tooltip="true"
            align="center"
            :key="index2"
            :min-width="item2[2]"
          >
          </el-table-column>
        </template>
        <template v-else slot-scope="{ row }">
          <span>{{ row[item[1]] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150" align="center" fixed="right">
        <template slot-scope="{ row }">
          <template v-if="row.manage_drawMoney_status">
            <el-button
              type="danger"
              @click="delitem(row)"
              class="el-icon-delete"
            ></el-button>
          </template>
          <template v-if="row.manage_drawMoney_status == 3">
            <el-button type="success" @click="checkitem(row)"> 通过 </el-button>
          </template>
          <template v-if="row.manage_drawMoney_status == 2">
            <el-button type="warning" @click="checkitem(row)">审核中</el-button>
          </template>
          <template v-if="row.manage_drawMoney_status == 1">
            <el-button type="info" @click="checkitem(row)">初始录入</el-button>
          </template>
          <template v-if="row.manage_drawMoney_status == 4">
            <el-button type="danger" @click="checkitem(row)">驳回</el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { apiDelDrawFunds } from "@/request/api.js";
export default {
  name: "canAddTable",
  data() {
    return {
      DataList: this.rows,
      // ischeck: true,
      isadd: true,
      activeId: 0
    };
  },
  props: {
    header: Array,
    rows: {
      type: Array,
      default: () => {
        return [];
      }
    }
  },
  watch: {
    rows(val) {
      this.DataList = val;
    }
  },
  methods: {
    //删除
    delitem(row) {
      let data = {
        manage_drawMoney_id: row.manage_drawMoney_id
      };
      console.log(data);
      this.$confirm(`确定删除吗？`)
        .then(() => {
          apiDelDrawFunds(data).then(res => {
            this.$message.success(res.msg);
            this.$emit("reload");
          });
        })
        .catch();
    },
    //开票
    print(row) {
      console.log(row);
      this.$emit("secondButton", row.manage_drawMoney_id);
    },
    //查看
    checkitem(row) {
      this.$emit("thirdButton", row.manage_drawMoney_id);
    },
    addline() {
      this.$emit("fristButton");
    },
    undoadd() {
      this.DataList.pop();
    },
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return `background: ${
          this.$store.state.tableColor
        };color:#fff;height:40px;padding:0px;`;
      } else {
        return "height:40px;padding:0px;";
      }
    },
    //计算合计
    computeSummary({ columns, data }) {
      let SummaryArr = ["", "", "", "", "收款合计", 0, ""];
      data.forEach(item => {
        if (item.manage_reqfunds_receiveAmount) {
          SummaryArr[5] += Number(item.manage_reqfunds_receiveAmount);
        }
      });
      this.$emit("receiveAmount", SummaryArr[5]);
      return SummaryArr;
    }
  }
};
</script>

<style lang="scss">
.el-table--border td:first-child .cell {
  padding-left: 0;
}
.el-table td .cell {
  padding: 0;
  line-height: 30px;
}
.el-table--small td {
  padding: 0;
}
</style>
